package com.gaohe.post.controller;

import java.util.List;
import java.io.IOException;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.gaohe.common.log.annotation.Log;
import com.gaohe.common.log.enums.BusinessType;
import com.gaohe.common.security.annotation.RequiresPermissions;
import com.gaohe.post.domain.FmPostContact;
import com.gaohe.post.service.IFmPostContactService;
import com.gaohe.common.core.web.controller.BaseController;
import com.gaohe.common.core.web.domain.AjaxResult;
import com.gaohe.common.core.utils.poi.ExcelUtil;
import com.gaohe.common.core.web.page.TableDataInfo;

/**
 * 帖子联系Controller
 * 
 * @author ruoyi
 * @date 2025-06-03
 */
@RestController
@RequestMapping("/contact")
public class FmPostContactController extends BaseController
{
    @Autowired
    private IFmPostContactService fmPostContactService;

    /**
     * 查询帖子联系列表
     */
    @RequiresPermissions("post:contact:list")
    @GetMapping("/list")
    public TableDataInfo list(FmPostContact fmPostContact)
    {
        startPage();
        List<FmPostContact> list = fmPostContactService.selectFmPostContactList(fmPostContact);
        return getDataTable(list);
    }

    /**
     * 导出帖子联系列表
     */
    @RequiresPermissions("post:contact:export")
    @Log(title = "帖子联系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FmPostContact fmPostContact)
    {
        List<FmPostContact> list = fmPostContactService.selectFmPostContactList(fmPostContact);
        ExcelUtil<FmPostContact> util = new ExcelUtil<FmPostContact>(FmPostContact.class);
        util.exportExcel(response, list, "帖子联系数据");
    }

    /**
     * 获取帖子联系详细信息
     */
    @RequiresPermissions("post:contact:query")
    @GetMapping(value = "/{postContactId}")
    public AjaxResult getInfo(@PathVariable("postContactId") Long postContactId)
    {
        return success(fmPostContactService.selectFmPostContactByPostContactId(postContactId));
    }

    /**
     * 新增帖子联系
     */
    @RequiresPermissions("post:contact:add")
    @Log(title = "帖子联系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FmPostContact fmPostContact)
    {
        return toAjax(fmPostContactService.insertFmPostContact(fmPostContact));
    }

    /**
     * 修改帖子联系
     */
    @RequiresPermissions("post:contact:edit")
    @Log(title = "帖子联系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FmPostContact fmPostContact)
    {
        return toAjax(fmPostContactService.updateFmPostContact(fmPostContact));
    }

    /**
     * 删除帖子联系
     */
    @RequiresPermissions("post:contact:remove")
    @Log(title = "帖子联系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{postContactIds}")
    public AjaxResult remove(@PathVariable Long[] postContactIds)
    {
        return toAjax(fmPostContactService.deleteFmPostContactByPostContactIds(postContactIds));
    }
}
